package com.zzxx.mapper;

import com.zzxx.entity.User;
import com.zzxx.entity.UserExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface UserMapper {
    @SelectProvider(type=UserSqlProvider.class, method="countByExample")
    long countByExample(UserExample example);

    @DeleteProvider(type=UserSqlProvider.class, method="deleteByExample")
    int deleteByExample(UserExample example);

    @Delete({
        "delete from user",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @Insert({
        "insert into user (id, username, ",
        "password, birthday, ",
        "phoneNum, identityNum, ",
        "sex, status, email, ",
        "realName, src, money)",
        "values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{birthday,jdbcType=DATE}, ",
        "#{phonenum,jdbcType=CHAR}, #{identitynum,jdbcType=CHAR}, ",
        "#{sex,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{email,jdbcType=VARCHAR}, ",
        "#{realname,jdbcType=VARCHAR}, #{src,jdbcType=VARCHAR}, #{money,jdbcType=DOUBLE})"
    })
    int insert(User row);

    @InsertProvider(type=UserSqlProvider.class, method="insertSelective")
    int insertSelective(User row);

    @SelectProvider(type=UserSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="birthday", property="birthday", jdbcType=JdbcType.DATE),
        @Result(column="phoneNum", property="phonenum", jdbcType=JdbcType.CHAR),
        @Result(column="identityNum", property="identitynum", jdbcType=JdbcType.CHAR),
        @Result(column="sex", property="sex", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="realName", property="realname", jdbcType=JdbcType.VARCHAR),
        @Result(column="src", property="src", jdbcType=JdbcType.VARCHAR),
        @Result(column="money", property="money", jdbcType=JdbcType.DOUBLE)
    })
    List<User> selectByExample(UserExample example);

    @Select({
        "select",
        "id, username, password, birthday, phoneNum, identityNum, sex, status, email, ",
        "realName, src, money",
        "from user",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="birthday", property="birthday", jdbcType=JdbcType.DATE),
        @Result(column="phoneNum", property="phonenum", jdbcType=JdbcType.CHAR),
        @Result(column="identityNum", property="identitynum", jdbcType=JdbcType.CHAR),
        @Result(column="sex", property="sex", jdbcType=JdbcType.INTEGER),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="realName", property="realname", jdbcType=JdbcType.VARCHAR),
        @Result(column="src", property="src", jdbcType=JdbcType.VARCHAR),
        @Result(column="money", property="money", jdbcType=JdbcType.DOUBLE)
    })
    User selectByPrimaryKey(String id);

    @UpdateProvider(type=UserSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("row") User row, @Param("example") UserExample example);

    @UpdateProvider(type=UserSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("row") User row, @Param("example") UserExample example);

    @UpdateProvider(type=UserSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(User row);

    @Update({
        "update user",
        "set username = #{username,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "birthday = #{birthday,jdbcType=DATE},",
          "phoneNum = #{phonenum,jdbcType=CHAR},",
          "identityNum = #{identitynum,jdbcType=CHAR},",
          "sex = #{sex,jdbcType=INTEGER},",
          "status = #{status,jdbcType=INTEGER},",
          "email = #{email,jdbcType=VARCHAR},",
          "realName = #{realname,jdbcType=VARCHAR},",
          "src = #{src,jdbcType=VARCHAR},",
          "money = #{money,jdbcType=DOUBLE}",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(User row);
}